# -*- coding: utf-8 -*-


from sqlalchemy import Column, String, BigInteger, PickleType, DateTime, Integer

from bopress.orm import Entity, many_to_one

__author__ = 'yezang'


class Options(Entity):
    option_id = Column(BigInteger().with_variant(Integer, "sqlite"),
                       autoincrement=True, nullable=False, primary_key=True)
    option_name = Column(String(255), nullable=False, default="")
    option_value = Column(PickleType, nullable=False)
    # yes or no
    autoload = Column(String(20), nullable=False, default="yes")


class Users(Entity):
    user_id = Column(BigInteger().with_variant(Integer, "sqlite"), autoincrement=True, nullable=False, primary_key=True)
    user_login = Column(String(100), nullable=False, unique=True)
    user_pass = Column(String(255), nullable=False)
    user_nicename = Column(String(50), nullable=False, default='')
    user_email = Column(String(100), nullable=False, default='')
    user_mobile_phone = Column(String(20), nullable=False, default='')
    user_url = Column(String(100), nullable=False, default='')
    # 注册时间
    user_registered = Column(DateTime, nullable=False)
    user_activation_key = Column(String(255), nullable=False, default='')
    # 0 未激活 1 已激活
    user_status = Column(Integer, nullable=False, default=0)
    display_name = Column(String(255), nullable=False, default='')


@many_to_one(Users)
class UserMeta(Entity):
    meta_id = Column(BigInteger().with_variant(Integer, "sqlite"), autoincrement=True, nullable=False, primary_key=True)
    meta_key = Column(String(255), nullable=False, default='')
    meta_value = Column(PickleType, nullable=False)


@many_to_one(Users)
class UserRole(Entity):
    role_id = Column(BigInteger().with_variant(Integer, "sqlite"), autoincrement=True, nullable=False, primary_key=True)
    role_name = Column(String(50), nullable=False)


@many_to_one(Users)
class UserObjectPermissions(Entity):
    user_object_permission_id = Column(BigInteger().with_variant(Integer, "sqlite"),
                                       autoincrement=True, nullable=False, primary_key=True)
    cls_name = Column(String(100), nullable=False)
    perm = Column(String(100), nullable=False)


@many_to_one(UserObjectPermissions)
class ObjectPermissions(Entity):
    object_permission_id = Column(BigInteger().with_variant(Integer, "sqlite"),
                                  autoincrement=True, nullable=False, primary_key=True)
    object_id = Column(String(40), nullable=False)
